<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>13</div>
    <!-- <p>14</p> -->
</body>
<script>
    // 数据
    class Subject {
        constructor(data) {
            this.data = data
            this.observers = []; //观察者列表
        }
        // 添加观察者
        addObserver(observer) {
            observer.update(this.data)
            this.observers.push(observer)
        }
        setData(newVal) {
            this.data = newVal
            this.observers.forEach(item => item.update(newVal))
        }
    }
    // 视图
    class Observer {
        constructor(name) {
            this.name = name
        }
        update(val) {
            this.name.textContent = val;
        }
    }
    var div = document.querySelector('div');
    let s1 = new Subject(0);
    s1.addObserver(new Observer(div))
    // setInterval(()=>{
    //     s1.setData(++s1.data)
    // },1000)
    

    var data = {
        test:{
            msg : 1
        }
    };
    var a = {}; var b = {};
    a.__proto__ = data ;
    b.__proto__ = data;
    a.test.msg=2;
    console.log(b.test.msg);
</script>

</html>